SDCC = /Developer/sdcc/bin/sdcc
SDAS8051 = /Developer/sdcc/bin/sdas8051
BUILDROOT = $(realpath .)

INCLUDES = -I$(BUILDROOT) \
-I$(BUILDROOT)/bm-br1 \
-I$(BUILDROOT)/HAL/include \
-I$(BUILDROOT)/HAL/source \
-I$(BUILDROOT)/wbsl \
-I$(BUILDROOT)/usb \
-I$(BUILDROOT)/usb/class_cdc \
-I$(BUILDROOT)/usb/library \
-I$(BUILDROOT)/usb/library/ccxx11 \
-I$(BUILDROOT)/sync \
-I$(BUILDROOT)/simpliciti \
-I$(BUILDROOT)/simpliciti/Components/bsp \
-I$(BUILDROOT)/simpliciti/Components/bsp/drivers \
-I$(BUILDROOT)/simpliciti/Components/bsp/mcus \
-I$(BUILDROOT)/simpliciti/Components/bsp/boards/RFUSB \
-I$(BUILDROOT)/simpliciti/Components/mrfi \
-I$(BUILDROOT)/simpliciti/Components/nwk \
-I$(BUILDROOT)/simpliciti/Components/nwk_applications \
-I$(BUILDROOT)/simpliciti/Configuration \
"-I$(BUILDROOT)/simpliciti/Configuration/Access Point"

CFLAGS += $(INCLUDES) -Dchip=1111 -DMRFI_CC1111 -DISM_LF --model-large -DRF_FREQUENCY=433000 --disable-warning 85 --stack-auto --opt-code-size

# Pattern rules for SDCC.
%.rel: %.c
	$(SDCC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@

%.rel: %.asm
	$(SDAS8051) $(INCLUDES) -x -o $@ -l usb/class_cdc/usb_cdc_descriptor.lst $<


OBJS = \
flash.rel \
main.rel \
timer1.rel \
HAL/source/hal_int.rel \
HAL/source/hal_mcu.rel \
HAL/source/clock.rel \
usb/class_cdc/usb_uart.rel \
usb/class_cdc/usb_cdc_descriptor.rel \
usb/class_cdc/usb_cdc_hooks.rel \
usb/class_cdc/usb_firmware_library_config.rel \
usb/library/ccxx11/usb_interrupt.rel \
usb/library/ccxx11/usb_suspend.rel \
usb/library/usb_framework.rel \
usb/library/usb_descriptor_parser.rel \
usb/library/usb_standard_requests.rel \
simpliciti/Components/bsp/bsp.rel \
simpliciti/Components/mrfi/mrfi.rel \
simpliciti/Components/nwk/nwk_api.rel \
simpliciti/Components/nwk/nwk.rel \
simpliciti/Components/nwk/nwk_frame.rel \
simpliciti/Components/nwk_applications/nwk_freq.rel \
simpliciti/Components/nwk_applications/nwk_ioctl.rel \
simpliciti/Components/nwk_applications/nwk_join.rel \
simpliciti/Components/nwk_applications/nwk_link.rel \
simpliciti/Components/nwk_applications/nwk_mgmt.rel \
simpliciti/Components/nwk_applications/nwk_ping.rel \
simpliciti/Components/nwk_applications/nwk_security.rel \
simpliciti/Components/nwk/nwk_globals.rel \
simpliciti/Components/nwk/nwk_QMgmt.rel \
simpliciti/Applications/main_AP_BM.rel \
wbsl/wbsl.rel

main: $(OBJS)
	$(SDCC) $(CFLAGS) -L /Developer/sdcc/share/sdcc/lib/large -o main.hex $(OBJS)

clean:
	rm $(OBJS)